package com.shenma2009.controller;

import com.shenma2009.domain.ResultResponse;
import com.shenma2009.service.TbUploadFileService;
import com.shenma2009.utils.AliyunOssUtil;
import com.shenma2009.vo.UploadImageResultWang;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 军哥
 * @version 1.0
 * @description: TbUploadFileController
 * @date 2023/4/22 11:33
 */

@RestController
@Slf4j
@RequestMapping(value = "/file")
public class TbUploadFileController {

    @Autowired
    TbUploadFileService tbUploadFileService;

    @PostMapping(value = "/upload")
    public ResultResponse uploadFile(@RequestParam("file") MultipartFile file, HttpServletRequest request) {

        String token = request.getHeader("token");
        log.info("token="+token);

        return tbUploadFileService.upload(file);

    }

    @PostMapping(value = "/uploadWang")
    public UploadImageResultWang uploadWang(HttpServletRequest request, @RequestParam("file") MultipartFile file) {

        String token = request.getHeader("token");
        log.info("token="+token);

        return tbUploadFileService.uploadWang(token, file);

    }
}
